<?php
function smarty_function_html_messages($params, $template)
{
  $messages = getMessages();
  $output = [];
  foreach ($messages as $message) {
    if ($message['type'] == 'error') {
      $class = 'alert-danger';
      $icon = '<i class="fa fa-times"></i> ';
    } else if ($message['type'] == 'success') {
      $class = 'alert-success';
      $icon = '<i class="fa fa-check"></i> ';
    } else if ($message['type'] == 'warning') {
      $class = 'alert-warning';
      $icon = '<i class="fa fa-warning"></i> ';
    } else {
      $class = 'alert-info';
      $icon = '<i class="fa fa-info"></i> ';
    }
    $output[] = <<<HTML
<div class="alert {$class}">
  <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
  <p>{$icon}{$message['value']}</p>
</div>
HTML;
  }
  return implode(PHP_EOL, $output);
}
